/*
 ============================================================================
 Name		: FbContentWindow.h
 Author	  : ceze
 Version	 : 1.0
 Copyright   : FlashBox for ver.Zhongyou(���ʰ�)
 Description : CFbContentWindow 内容显示窗口
 ============================================================================
 */

#ifndef FBCONTENTWINDOW_H
#define FBCONTENTWINDOW_H

// INCLUDES
#include <coecntrl.h>
#include <documenthandler.h> 
#include <aknserverapp.h> 

#include "fbtabgroupleft.h"
#include "fbtabobserver.h"
#include "FbList.h"
#include "ConstDefined.hrh"
#include "WebClientEngine.h"
#include "XmlHandler.h"
#include "XmlNode.h"
#include "FbProgressBar.h"
#include "DeCompresszip.h"
#include "Flashbox4.hrh"
// CLASS DECLARATION
class CRfsEngine;
/**
 *  CFbContentWindow
 */
class CFbContentWindow : public CCoeControl,
		MFbTabObserver,
		MListObserver,
		MWebClientObserver,
		MXmlHandlerObserver,
		MAknServerAppExitObserver 
{
public:
	// Constructors and destructor

	/**
	 * Destructor.
	 */
	~CFbContentWindow ();

	/**
	 * Constructor for performing 1st stage construction
	 */
	CFbContentWindow ();

	/**
	 * EPOC default constructor for performing 2nd stage construction
	 */
	void ConstructL (const TRect& aRect, CCoeControl *pParent );

	/**
	 * 派生自MFbTabObserver接口
	 * 处理tab切换事件
	 */
	void TabChangedL (TInt aTabIndex, TInt aTabId );

	/**
	 * 切换内容
	 */
	void SwitchContentL (TInt aContentId );

	/**
	 * 取得内容id
	 */
	TInt GetContentId ();

	/*
	 * From CoeControl,
	 * 按键事件接收处理
	 */
	TKeyResponse OfferKeyEventL (const TKeyEvent &aKeyEvent, TEventCode aType );

	
	/**
	 * 获取网络服务器内容
	 */
	void QueryDataByHttpL (const TInt aContentId, const TDataQueryTpey queryType);
	
	/**
	 * 取消网络连接
	 */
	void CancelHttpQueryL();
	
	
	/**
	 * 栏目切换
	 */
	void ChangeToCategory(const TContentsType type, const TStoreType aStoreType);
	
	/**
	 * 取得栏目类别
	 */
	TInt GetCategoryType();
	
	/**
	 * from CCoeControl
	 */
	void MakeVisible(TBool aVisible);
	
	/**
	 * 处理选项菜单消息！
	 */
	void HandleParentOptionMsg(TInt aOptionId);
	
	/*
	 * Get the stored type!
	 */
	TInt GetStoreType();
	
	/**
	 * 处理选项菜单消息！
	 */
	void HandleParentEjectOptionMsg(TInt aEjectOptionId);	

protected:
	
	/**
	 * from MListObserver
	 * pHandle 发出消息的对象
	 * aItemIndex:激活的item 序号
	 * aEventType:事件类型
	 */
	void ListItemEvent (CFbList *pHandle, TInt aItemIndex, TInt aItemId, TInt aEventType );

	////////////////////MWebClientObserver接口函数//////////////
	/**
	 * WebClientEvent()
	 * Called when event occurs in CWebClientEngine.
	 * @param aEventDescription: A event in textual format, e.g.
	 *                           "Transaction Successful"
	 */
	void WebClientEvent (const TInt aEvent,TInt aSessionId,/*const TDesC& aEventDescription,*/
	TInt aCode = 0);

	/**
	 * WebClientHeaderReceived()
	 * Called when HTTP header is received.
	 * @param aHeaderData: Header field name and value
	 */
	void WebClientHeaderReceived (const TDesC8& aHeaderFiled, const TDesC8& aHeaderVal, TInt aSessionId );

	/**
	 * WebClientBodyReceivedComplete()
	 * Called when a part of the HTTP body is received.
	 * @param aBodyData:  Part of the body data received. (e.g. part of
	 *                    the received HTML page)
	 */
	void WebClientBodyReceivedComplete (const TDesC8& aBodyData , TInt aSessionId);
	
	
	void ClientBodyReceived (const TDesC8& aBodyData, TBool aIsLast );
	/////////////////////MXmlHandlerObserver接口/////////////////
	//文件解析完成
	void OnXmlNodeParseCompletedL (TInt aError,CXmlNode *pNode,TInt aSession);
	
	//MAknServerAppExitObserver 
	void  HandleServerAppExit (TInt aReason);
private:
	
	/**
	 * 开始显示滚动条
	 */
	void StartToShowProgressBar();
	
	/**
	 * 设置滚动条的数据总量
	 */
	void SetProgressBarDataLength(TInt aLen);
	
	/**
	 * 更新滚动条
	 * step 增加步长
	 */
	void UpdateProgressBar(TInt step);
	
	/**
	 * 停止滚动条
	 */
	void StopProgressBar();
	
	/**
	 * 加载数据,到List
	 */
	void LoadDataL (TInt aConType, TStoreType aStoreType );

	/**
	 * From CoeControl,CountComponentControls.
	 */
	TInt CountComponentControls () const;

	/**
	 * From CCoeControl,ComponentControl.
	 */
	CCoeControl* ComponentControl (TInt aIndex ) const;

	/**
	 * From CCoeControl
	 */
	void SizeChanged ();

	/**
	 * From CCoeControl, Draw
	 * Draw this CFbTabgroup to the screen.
	 * @param aRect the rectangle of this view that needs updating
	 */
	void Draw (const TRect& aRect ) const;

	/**
	 * 初始化Tab组件(left)
	 */
	void InitializeTabGroupL (CFbTabgroupLeft *pTabgroup );
	
	/**
	 * 载入List列表数据(普通内容)
	 */
	void SetupListCommonDataL(CXmlNode *pDataNode);
	
	/**
	 * List本地内容点击
	 */
	void ListItemSelectedLocalL(const TInt aIndex);
	
	/**
	 * List远程内容点击
	 */
	void ListItemSelectedRemoteL(const TInt aIndex);
	
	/**
	 * 更新选项菜单
	 */
	void UpdateOptionMenu(TInt aEvent);
	/*
	 * 
	 */
	void OpenFileEmbeddedL(const TDesC &aFileName);
	
private:
	TInt			m_categoryType;//栏目分类
	TInt			m_contentsType;//加载内容类型
	TInt			m_storeType; 	//存储类型
	TInt			m_httpQueryType;	//查询类型
	CFbTabgroupLeft *m_pLeftTabgroup;
	CRfsEngine 		*m_pRfsEngine;
	CXmlHandler		*m_pXmlHandler;	//xml解析器
	
	//CXmlNode		*m_pContextNodeRemote;//远程数据节点
	CXmlNode		*m_pContextNodeLocal; //本地数据节点
	CFbListData		*m_pListItemSelected;//被操作的项,数据下载时使用临时变量,不需释放内存
	TInt 			m_querySessionId;
	//CDocumentHandler
	CDocumentHandler *m_pDocHandler;
	CFbProgressBar	 *m_pProgressBar;//进度滚动条
	CCoeControl		 *m_pParent;//无需释放内存
	CDeCompressZip	 *m_pDezip;
	
public:
	CFbList *m_pContentList;//内容列表

};

#endif // FBCONTENTWINDOW_H
